<?php
require_once 'BaseController.php';

/**
 * 路線図検索クラス<br />
 *
 * @package    apamanshop
 * @author     imamura-h@systemsoft.co.jp
 * @copyright
 */
class Search_RosenzusearchController extends Search_BaseController
{
	public function indexAction()
	{
		$this->setMainTemplate('cms_search.tpl');

		/*
		 * 基本情報設定
		 */

		if (Apm_Config_Search::RENEW_2012) {
			$this->_display_path = APPLICATION_PATH . '/modules/search/views/scripts/search_new.tpl';
			$this->_newTemplate = true;
			$this->_import_seo_search = true;
			// テンプレート変更
			$this->_todohuken_radio_helper = $this->getApmHelper('seltodohuken_radio_new.tpl');
			$this->_eki_rosenzu_helper     = $this->getApmHelper('seleki_rosenzu_new.tpl');
			// JavaScript
			$this->addMetaJs('/common_new/js/import.js');
		} else {
			$this->_display_path = APPLICATION_PATH . '/modules/search/views/scripts/search.tpl';
			//CSSの定義（デザイン）
			$this->addMetaCss('/css/search/search.css',array('type' => 'text/css','media' => 'all'));
			$this->addMetaCss('/css/rail/rail.css',array('type' => 'text/css','media' => 'all'));
			$this->addMetaCss('/css/shop/shop.css',array('type' => 'text/css','media' => 'all'));
			//JavaSriptの定義（アプリ）
			$this->addMetaJs('/app/js/search/InputChk.js');
			$this->addMetaJs('/app/js/search/SelRouteMap.js');
		}

		// 駅すぱあとKey
		$this->_data['ekispert']['url'] = $this->_config['ekispert']['url'];
		$this->_data['ekispert']['key'] = $this->_config['ekispert']['key'];
		// 駅すぱあとAPIをローカルJSで実行
		if (empty($this->_data['ekispert']['key']))
		{
			$this->addMetaJs('/app/js/search/val/authentication.js',array('charset' => 'Shift_JIS'));
			$this->addMetaJs('/app/js/search/val/CSize.js',array('charset' => 'Shift_JIS'));
			$this->addMetaJs('/app/js/search/val/CPoint.js',array('charset' => 'Shift_JIS'));
			$this->addMetaJs('/app/js/search/val/CMap.js',array('charset' => 'Shift_JIS'));
			$this->addMetaJs('/app/js/search/val/CUserInterface.js',array('charset' => 'Shift_JIS'));
			$this->addMetaJs('/app/js/search/val/CMapApp.js',array('charset' => 'Shift_JIS'));
			$this->addMetaJs('/app/js/search/val/CServletMap.js',array('charset' => 'Shift_JIS'));
			$this->addMetaJs('/app/js/search/val/CService.js',array('charset' => 'Shift_JIS'));
			$this->addMetaJs('/app/js/search/val/CHTTPConnection.js',array('charset' => 'Shift_JIS'));
			$this->addMetaJs('/app/js/search/val/CEnvironment.js',array('charset' => 'Shift_JIS'));
			$this->addMetaJs('/app/js/search/val/CExpStation.js',array('charset' => 'Shift_JIS'));
			$this->addMetaJs('/app/js/search/val/CMapPoint.js',array('charset' => 'Shift_JIS'));
			$this->addMetaJs('/app/js/search/val/CBounds.js',array('charset' => 'Shift_JIS'));
			$this->addMetaJs('/app/js/search/val/CImage.js',array('charset' => 'Shift_JIS'));
			$this->addMetaJs('/app/js/search/val/CMark.js',array('charset' => 'Shift_JIS'));
			$this->addMetaJs('/app/js/search/val/CBalloon.js',array('charset' => 'Shift_JIS'));
			$this->addMetaJs('/app/js/search/val/CExpApp.js',array('charset' => 'Shift_JIS'));
			$this->addMetaJs('/app/js/search/val/CExpRangeStation.js',array('charset' => 'Shift_JIS'));
		}
		else
		{
	    	$this->addMetaJs($this->_data['ekispert']['url'] . $this->_data['ekispert']['key']);
		}

    	// グローバルナビから遷移してきた場合
		if ($this->isGlobalNavi())
		{
//			Apm_Util_GlobalNavi_Common::transitionJudge(Apm_Config_Search::SRHKBN_ROSENZU);
			$this->_params = Apm_Util_GlobalNavi_Common::transitionJudge(Apm_Config_Search::SRHKBN_ROSENZU);
			// パラメータの補足
			Apm_Bukkenurl::convertSearchParam($this->_params);
			// canonical
			$this->addMetaCanonical($this->_baseurl . 'search/rosenzusearch/');
		}

		// 検索区分
		$this->setSearchKbn(Apm_Config_Search::SRHKBN_ROSENZU, "rosenzusearch");

		/*
		 * モデルオブジェクト生成
		 */
		// 路線図検索
		$this->_model_rosenzu  = new Search_Model_Rosenzu();

		/*
		 * 検索画面振り分け
		 */
        // 都道府県検索
        // (初期呼び出し時)
		if (!$this->_model_common->checkvalue($this->_params, "PrefCd") || count($this->_params['PrefCd']) != 1)
		{
			// 都道府県コードの破棄
			unset($this->_params['PrefCd']);
			if ($this->_newTemplate) {
				// CSS
				$this->addMetaCss('/common_new/css/sub02.css',array('type' => 'text/css','media' => 'all'));
				// ブロックタイトル
				$this->_data['block_title'] = '*路線図から賃貸情報を探す';
				// 人気のエリアtpl読み込み
				$pop_tpl = $this->getApmHelper(APPLICATION_PATH . '/modules/common/views/helpers/pop_area.tpl');
				$this->_data['pop_area_block'] = $pop_tpl->getBlock("");
			} else {
				// H1のタイトル
				$this->_data['h1_title'] = 'ご希望の都道府県をクリックしてください。';
				// JavaScript
				$this->addMetaJs('/app/js/search/Seltodohuken.js');
			}
			
			// 画面遷移区分
			$this->_data['next_search'] = "EKI";

			$this->_main_helper = $this->_todohuken_radio_helper;

		}
		// 駅検索
		else if ($this->_model_common->checkvalue($this->_params, "ekiword"))
		{
			// 空白を取り除く
			$this->_params['ekiword'] = mb_ereg_replace("　", "", mb_ereg_replace(" ", "", $this->_params['ekiword']));
			// ページNo初期化
			if (!$this->_model_common->checkvalue($this->_params, "page_no")) $this->_params['page_no'] = "1";
			// 件数検索
			$this->_data['ekiCount'] = $this->_model_rosenzu->getEkiCount($this->_params);
			$this->_data['ekiList']  = array();
			// 1件以上存在する場合
			if ($this->_data['ekiCount']['CNT'] > 0)
			{
				// 駅一覧取得
				$this->_data['ekiList'] = $this->_model_rosenzu->getEkiList($this->_params);
			}
			// 表示用データに変換
			$this->_data['page'] = $this->_model_rosenzu->convertEkiList($this->_params, $this->_data);

			// 路線図用・駅物件数検索
			$this->_data['bkncnt'] = $this->_model_rosenzu->getBukkenCntList();

			if ($this->_newTemplate) {
				// CSS
				$this->addMetaCss('/common_new/css/sub03.css',array('type' => 'text/css','media' => 'all'));
				$this->addMetaCss('/css/rail/rail.css',array('type' => 'text/css','media' => 'all'));
				// ブロックタイトル
				$this->_data['block_title'] = '*路線図から賃貸情報を探す';
			} else {
				// H1のタイトル
				$this->_data['h1_title'] = '路線図から探す&nbsp;&gt;&gt;&nbsp;検索結果から駅を選択してください。';
			}

			// パンくずの編集をしない
			$this->_noMakeBreadcrumb = true;

			// ブロック生成
			$this->_main_helper = $this->_eki_rosenzu_helper;
		}
		// 路線図検索
		else
		{
			// 路線図用・駅物件数検索
			$this->_data['bkncnt'] = $this->_model_rosenzu->getBukkenCntList();
			
			if ($this->_newTemplate) {
				// CSS
				$this->addMetaCss('/common_new/css/sub03.css',array('type' => 'text/css','media' => 'all'));
				$this->addMetaCss('/css/rail/rail.css',array('type' => 'text/css','media' => 'all'));
				// ブロックタイトル
				$this->_data['block_title'] = '*路線図から賃貸情報を探す';
			} else {
				// H1のタイトル
				$this->_data['h1_title'] = '路線図から検索';
			}

			if ($this->_model_common->checkvalue($this->_params, "RsCd")) {
				// パンくずの編集をしない
				$this->_noMakeBreadcrumb = true;
				unset($this->_params['RsCd']);
			}

			// ブロック生成
			$this->_main_helper = $this->_eki_rosenzu_helper;
		}

		// 不要なパラメータを削除（hiddenから削す）
		for ($i=0; $i<10; $i++) {
			unset($this->_params['stcode']);
			unset($this->_params['station']);
			unset($this->_params['Restcode']);
			unset($this->_params['Restation']);
		}
	}

}
?>